// 直接放行的接口
module.exports = async (ctx, next) => {
  const url = ctx.request.url.split('?')[0];
  const _token = ctx.headers["authorization"];
  if (url.indexOf('public') === -1 && !_token) {
    ctx.status = 401;
    ctx.body = { error: "No token provided" };
    return;
  }
  try {
    await next();
  } catch (err) {
    ctx.status = 401;
    ctx.body = { error: "Invalid token" };
  }
};
